home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Business & Presentations
/
Business and Presentations - Volume 1 (1995)(Sideface)(NL).iso
/
hputils
/
djprnt
/
line.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1990-02-10
|
2KB
|
58 lines
/*
LINE.CPP
Copyright (c) Les Hancock 1990
*/
#include <stdio.h>
#include <string.h>
#include <stream.hpp>
#include "list.hpp"
#include "parms.hpp"
#include "line.hpp"
#include <stdlib.h>
/*
Friend function. Use input stream to fill a line exactly <size> bytes long.
*/
istream& operator>>(istream& in, line& a_line)
{
register unsigned int n = a_line.size;
register char *ptr = a_line.head;
while (n > 0) // while the line's not actually filled up
{
char ch;
in.get(ch);
if (in.bad() || in.eof() || in.fail()) // if can't read more from file
{
if (ptr == a_line.head) // if we got nothing this time
a_line.eof = 1; // set the flag that shows eof
break;
}
switch(ch) // what was that character anyway?
{
case '\t': // expand tab if enough room on line, else push back
if (n > a_line.tab_size)
{
memset(ptr, ' ', a_line.tab_size);
ptr += a_line.tab_size;
n -= a_line.tab_size;
}
else
{
in.putback(ch); // too big to handle, end line here
goto end_of_the_line;
} // falls through
case 0xd: // ignore CR, which comes in by itself
break;
case 0xa: // signals end of line
goto end_of_the_line;
default: // any other character, append to buffer
*ptr++ = ch;
--n;
}
}
end_of_the_line:
memset(ptr, ' ', n); // ... set blanks to end of line
return in;
}